package com.yiwenup.leetcode.offer;

import java.util.Stack;

/**
 * https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/
 *
 * 执行用时：18 ms, 在所有 Java 提交中击败了97.60%的用户
 * 内存消耗：40.5 MB, 在所有 Java 提交中击败了14.11%的用户
 **/
public class No030 {
    private Stack<Integer> normal, min;

    /**
     * initialize your data structure here.
     */
    public No030() {
        normal = new Stack<>();
        min = new Stack<>();
    }

    public void push(int x) {
        normal.push(x);
        if (min.isEmpty() || x <= min.peek()) min.push(x);
    }

    public void pop() {
        int pop = normal.pop();
        if (min.peek() == pop) min.pop();
    }

    public int top() {
        return normal.peek();
    }

    public int min() {
        return min.peek();
    }
}
